package com.mybatistest.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mybatistest.entity.Result;
import com.mybatistest.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper extends BaseMapper<User> {
    @Insert("insert into t_user(name,age) values(#{name},#{age})")
    int insert(User user);

    @Update("update t_user set name = #{name}, age = #{age} where id = #{id}")
    boolean updateUser(User user);

    /*@Select("SELECT name, NULL as citizen, age FROM t_user WHERE name = #{name} " +
            "UNION " +
            "SELECT name, citizen, NULL as age FROM t_mybatis WHERE citizen LIKE CONCAT('%', #{citizen}, '%')" +
            "order by")
    List<Result> queryByName(@Param("name") String name, @Param("citizen") String citizen);*/

    @Select("SELECT u.name, m.citizen, u.age FROM t_mybatis AS m " +
            "INNER JOIN t_user AS u ON u.name = m.name " +
            "WHERE u.age >= #{age}")
    List<Result> queryByName(@Param("age") int age);

    Integer totalCount(@Param("name") String name);
}
